<template>
  <div class="custom-container" style="padding: 10px;">
    <el-container direction="vertical">
      <el-card shadow="always">
        <el-form :inline="true">
          <el-form-item label="场景分类：">
            <el-select v-model="form.sceneClassification" clearable filterable>
              <el-option v-for="(item,index) in sceneClassification" :key="index" :label="item.dictLabel"
                :value="item.dictValue"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="创建人：">
            <el-input v-model="form.createUser"></el-input>
          </el-form-item>
          <el-form-item label="压测场景名称：">
            <el-input v-model="form.sceneName"></el-input>
          </el-form-item>
          <el-form-item label="创建时间：">
            <el-date-picker v-model="form.timeList" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="daterange" range-separator="至"
              start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryPressurePages">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetForm">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <div style="padding: 10px 0">
        <el-button type="primary" @click="handleScene('add',{id : ''})">新增场景</el-button>
      </div>
      <el-main class="no-padding">
        <el-table border :data="tableList"  :row-style="customStyle" v-loading="loading">
          <el-table-column label="序号" align="center" width="50" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.$index + 1}}
            </template>
          </el-table-column>
          <el-table-column label="场景名称" align="center" prop="sceneName" show-overflow-tooltip></el-table-column>
          <el-table-column label="场景分类" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.sceneClassification == '1' ? '流量加压' : '政策加压'}}
            </template>
          </el-table-column>
          <el-table-column label="场景描述" align="center" prop="sceneRemake" show-overflow-tooltip></el-table-column>
          <!-- <el-table-column label="节点数/默认节点/自定义节点" align="center" prop="nodeInfoName" show-overflow-tooltip></el-table-column> -->
          <el-table-column label="创建人" align="center" prop="creatUser" show-overflow-tooltip></el-table-column>
          <el-table-column label="创建时间" align="center" prop="createTime" show-overflow-tooltip></el-table-column>
          <el-table-column label="操作" width="240" align="center">
            <template slot-scope="scope">
              <el-button type="text" @click="handleScene('see',scope.row)">流程节点图</el-button>
              <el-button type="text" @click="handleScene('edit',scope.row)">编辑</el-button>
              <el-button type="text" @click="handleScene('detail',scope.row)">详情</el-button>
              <span class="el-button el-button--medium del" @click="handleScene('delete',scope.row)">删除</span>
            </template>
          </el-table-column>
        </el-table>
        <div style="height: 50px;display: flex;align-items: center;justify-content: center;">
          <el-pagination background layout="prev, pager, next" :total="countTotal"
            @current-change="onPageChange"></el-pagination>
        </div>
      </el-main>
    </el-container>
    <el-dialog :title="'场景名称:' + dialogTitle" :visible.sync="dialogVisible" append-to-body center width="56%"
      @close="dialogVisible = false" custom-class="customDialog">
      <div class="configNode" style="width: auto;">
          <div class="node-item scroll-item" v-for="(item,index) in nodeConfigList" :key="index">
             <p class="name txt-center">流程{{ index + 1}}</p>
             <p class="flow" :class="{'ellipsis' : item.nodeName.length > 6}">{{item.nodeName}}</p>
             <div class="lines flex">
               <div class="line-item" :style="{backgroundColor:index === 0 ? 'transparent' : '#000'}"></div>
               <div class="center-round"></div>
               <div class="line-item" :style="{backgroundColor:index ===  nodeConfigList.length - 1 && index !== 0 ? 'transparent' : '#000'}"></div>
             </div>
             <div class="nodeCapacity" :title="item.nodeCapacity">
               {{item.nodeCapacity}}
             </div>
          </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { formatDate } from '@/utils'
  import { openMessage } from '../../../utils';
  export default {
    data() {
      return {
        tableList: [],
        loading: false, //加载
        sceneClassification: [], //场景分类
        countTotal: 1,
        dialogVisible: false, //弹窗是否展示
        dialogTitle: '', //弹窗标题
        form: {
          sceneClassification: '',
          pageNum: 1,
          pageSize: 10,
          createUser: '',
          sceneName: '',
          timeList: '',
        },
        nodeConfigList:[],
      }
    },
    methods: {
      customStyle: function({
        row,
        rowIndex
      }) {
        return 'height:20px'
      },
      resetForm() {
        this.form.sceneClassification = ''
        this.form.createUser = ''
        this.form.sceneName = ''
        this.form.timeList = ''
      },
      // 场景的功能事件
      handleScene(type, item) {
        if (type === 'add' || type === 'edit' || type === 'detail') {
          this.$router.push({
            path: '/stress/addScene',
            query: {
              type,
              id:item.id
            }
          })
        }
        switch (type) {
          case 'see': //流程节点图
            this.$request({
              url: `/hnzc/ylcs/jymn/hnzcSceneInfo/selectDetailById`,
              method: 'get',
              params: {
                id: item.id
              }
            }).then(({
              code,
              data
            }) => {
              if (code === 200) {
                this.dialogTitle = data.sceneName //场景名称
                this.nodeConfigList = data.nodeInfoList
                if (data.nodeInfoList && data.nodeInfoList.length === 0) {
                  openMessage('暂无流程节点','warning')
                  return
                }
                this.dialogVisible = true
              }
            })
            break;
          case 'delete': //删除场景
            this.$confirm('您确定要删除吗?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.$request({
                url: '/hnzc/ylcs/jymn/hnzcSceneInfo/delete',
                method: 'get',
                params: {
                  id: item.id
                }
              }).then(({
                code
              }) => {
                if (code === 200) {
                  this.$message({
                    type: 'success',
                    message: '删除成功!'
                  })
                  this.queryPressurePages()
                }
              })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消删除'
              });
            });
            break;
        }
      },
      // 查询表格数据
      queryPressurePages() {
        this.tableList = []
        let data = Object.assign({}, this.form)
        if (this.form.timeList instanceof Array) {
          data.startTime = this.form.timeList[0] + ' 00:00:00'
          data.endTime = this.form.timeList[1] + ' 23:59:59'
        } else {
          data.startTime = ''
          data.endTime = ''
        }
        delete data.timeList
        this.loading = true
        this.$request({
          url: '/hnzc/ylcs/jymn/hnzcSceneInfo/queryPageList',
          method: 'post',
          data
        }).then(({
          total,
          rows
        }) => {
          this.countTotal = total
          this.tableList = rows
          this.loading = false
          if (this.tableList && this.tableList.length > 0) {
            this.tableList.forEach(item => {
              item.createTime = formatDate(item.createTime)
            })
          }
        })
      },
      onPageChange(e) {
        this.form.pageNum = e
        this.queryPressurePages()
      },
      // 查询场景分类的
      querySceneClassification() {
        this.$request({
          url: '/system/dict/data/type/ylcs_cjfl',
          methed: 'get'
        }).then(({
          code,
          data
        }) => {
          if (code === 200) {
            this.sceneClassification = data
            let obj = {
              dictLabel:'所有',
              dictValue:'0'
            }
            this.sceneClassification.unshift(obj)
          }
        })
      },
    },
    created() {
      this.queryPressurePages()
      this.querySceneClassification()
    },
    computed: {

    },
  }
</script>
<style lang="scss" scoped>
  @import '@/assets/styles/nodeStyle.scss';
  .del {
    border-color: transparent;
    padding-left: 0;
    padding-right: 0;
    background: transparent;
    color: #f00;
  }
  .txt-center{
    text-align: center;
  }
  ::v-deep .el-dialog__body{
    padding: 15px 15px 30px!important;
  }
  .pt10 {
    padding: 10px 0;
  }
  .flex{
    display: flex;
  }
  .always-shadow {
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }

  .p10 {
    padding: 10px;

    .title {
      font-weight: bolder;
    }
  }
  .configNode{
    display: flex;
    height: 100%;
    overflow-x: auto;
    &::-webkit-scrollbar {
      height: 12px;
      border-radius: 10px;
    }
    &::-webkit-scrollbar-thumb {
      border-radius: 6px; /* 设置滑块圆角 */
      background-color: rgb(165,169,183);
    }
    &::-webkit-scrollbar-track {
      border-radius: 5px;
      background-color: transparent; /* 设置滚动条滑块颜色 rgb(165,169,183)*/
    }
    .node-item{
      margin-bottom: 12px;
    }
  }
</style>
